package com.dycong.common.IO.calculator.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 *
 * @author yangtao__anxpp.com
 * @version 1.0
 */
public class ClientReader implements Runnable{

    private static int DEFAULT_SERVER_PORT = 12345;
    private static String DEFAULT_SERVER_IP = "127.0.0.1";

    static Socket socket=null;
    public ClientReader(Socket socket){
        this.socket=socket;
    }
    @Override
    public void run(){
        send();
    }

    public static void send() {
        String expression="客户端循环读：";
        BufferedReader in = null;

        try {

            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String message="";
            while (true){
                if ((message=in.readLine())==null) continue;
                System.out.println(expression+message);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                in = null;
            }
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                socket = null;
            }
        }
    }
}